import time
from gen.libs import lib

log = lib.get_seq_logger()
uut = lib.conn.UUT


def test_case():
    uut.open()
    lib.ask_question("请输入产品的信息：")
    for _ in range(3):
        uut.send("pwd\r", expectphrase="]$", timeout=60)

        uut.send("free -h\r", expectphrase="]$", timeout=60)
        log.debug("RAM Usage:")
        log.debug(uut.recbuf.splitlines()[2])

        uut.send("sudo fdisk -l\r", expectphrase=["]$", "genesis:"], timeout=60)
        if "genesis:" in uut.recbuf:
            uut.send("genesis\r", expectphrase="]$", timeout=60)
        log.debug("HDD Usage:")
        for line in uut.recbuf.splitlines():
            if "/dev/sda1" in line:
                log.debug(line)

        uut.send("mpstat\r", expectphrase="]$", timeout=60)
        log.debug("CPU Usage:")
        for line in uut.recbuf.splitlines():
            if "all" in line:
                log.debug("{} %".format(line.split()[-1]))

        time.sleep(3)
        log.debug("Sleep 3s, 然后继续。。。")

    container_name = lib.get_container_name()
    log.debug("Current Container - [{}]".format(container_name))
    lib.add_test_data("DUMMY", "EXAMPLE", "PCBST", container_name)
    return
